# $Id: gnu.sh.in 586 2008-08-27 03:24:45Z enki $
#
# class/tempfile.sh: Gnu.org mining functions
#
# -------------------------------------------------------------------------
test $lib_class_tempfile_sh || {

# directory setup
# -------------------------------------------------------------------------
: ${prefix:="@prefix@"}
: ${exec_prefix:="@prefix@"}
: ${libdir:="${exec_prefix}/lib"}
: ${shlibdir:="${libdir}/sh"}

# load dependencies
# -------------------------------------------------------------------------
. $shlibdir/std/var.sh
. $shlibdir/shell/trap.sh

# static variables
# -------------------------------------------------------------------------
TEMPFILE_list=

# tempfile_new <variable-name> [options] [template]
# -------------------------------------------------------------------------
tempfile_new()
{
  TEMPFILE_var="$1"

  eval "TEMPFILE_path=\${$TEMPFILE_var}"

  if [ -n "$TEMPFILE_path" -a -e "$TEMPFILE_path" ]; then
    rm -f "$TEMPFILE_path"
  fi

  shift

  TEMPFILE_path=`mktemp "$@"`

  if [ -n "$TEMPFILE_path" -a -w "$TEMPFILE_path" ]; then
    eval "$TEMPFILE_var=\${TEMPFILE_path}"
    return 0
  fi

  return 1
}

# ---[ EOF ]---------------------------------------------------------------
lib_class_tempfile_sh=:;}
